package com.mike.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mike.common.Const;
import com.mike.pojo.T_emp;
import com.mike.service.impl.t_empService;
import com.opensymphony.xwork2.ModelDriven;




@Component("t_empAction")
public class t_empAction implements ModelDriven,RequestAware{

	@Autowired
	private t_empService t;
	
	Map<String, Object> requestMap = null;
	@Override
	public void setRequest(Map<String, Object> requestMap) {
		this.requestMap=requestMap;
		
	}

	private T_emp t_emp;
	@Override
	public Object getModel() {
		
		return t_emp;
	}
	
	public T_emp getT_emp() {
		return t_emp;
	}



	public void setT_emp(T_emp t_emp) {
		this.t_emp = t_emp;
	}


	
	private int page;
	
	
	public int getPage() {
		return page;
	}

	

	public void setPage(int page) {
		this.page = page;
	}

	
	private int empno;
	

	public int getEmpno() {
		return empno;
	}

	public void setEmpno(int empno) {
		this.empno = empno;
	}

	public String find(){
		int page = 1;
		System.out.println("进入action类里的find方法");
		List<T_emp> emps = t.findByPage(page,5).getList();
		int page1 = t.findByPage(page,5).getPageNo();
		requestMap.put("emps", emps);
		requestMap.put("page", page1);
		System.out.println("列出来");
		System.out.println("***************************************");
		return Const.SUCCESS;
	}

	public String queryfindpage(){
		//int page1 = (int) requestMap.get("page");
	
		System.out.println(getPage());
		System.out.println("进入action类里的find方法");
		
		List<T_emp> emps = t.findByPage(page,5).getList();
		int pageno = t.findByPage(page,5).getPageNo();
		
		requestMap.put("emps", emps);
		requestMap.put("page", pageno);
		System.out.println("列出来");
		
		System.out.println("***************************************");
		
		return Const.SUCCESS;
		
	}
	
	public String add(){
		System.out.println("进来add方法");
		//System.out.println(t_emp.toString());
		t.insert(t_emp);
		return Const.SUCCESS;
	}
	
	public String delete(){
		System.out.println("进来delete方法");
		t.delete(t_emp);
		return Const.SUCCESS;
		
	}
	
	public String update(){
		System.out.println("进来update方法");
		
		System.out.println(t_emp.getEmpno());
		t.update(t_emp);
		return Const.SUCCESS;
		
	}
	
	public String findById(){
		
		System.out.println("进来findById"+empno);
		T_emp emp = t.findById(empno);
		requestMap.put("emp", emp);
		System.out.println(emp);
		System.out.println("findById执行完成");
		return Const.SUCCESS;
		
	}
	
	
}
